/*
 * UART.cpp
 *
 *      Author: Christian
 *      Letztes Update: 11.01.14 Christian | fähler rausmachen
 *
 */



#include "UART.h"

	char send_buffer[SEND_BUFFER_SIZE];

	volatile char recieve_buffer[RECIEVE_BUFFER_SIZE];
	volatile uint8_t recieved_number = 0;


void UARTInit() {
	//BAUD-Rate einstellen
	UBRRH = ( uint8_t ) ( 103>> 8 );
	UBRRL = ( int8_t  ) 103;

	//Sender einstellen
	UCSRB = ( 1 << TXEN ) | ( 1 << RXEN ) | ( 1 << RXCIE );

	//Frame einstellen: 8data, 2stop bit
	UCSRC = ( 1 << URSEL ) | ( 1 << USBS ) | ( 1 << UCSZ0 ) | ( 1 << UCSZ1 );
}

void UART_send( uint8_t bytes ) {
	for( uint8_t i = 0; i < bytes; i++ ) {
		UDR = send_buffer[i];
		while( !( UCSRA & ( 1 << UDRE ) ) );
	}
}


ISR( USART_RXC_vect ) {

	recieve_buffer[recieved_number] = UDR;
	recieved_number++;

}



